package com.tengfei.main;

/**
 * @author feige
 * @version v1.0
 * @date 2022-09-21-9:39
 * @description Java静态代理
 */
public class JavaStaticProxy {

    public static void main(String[] args) {
        new JdkProxy(new ServiceImpl()).send("发送短信哈...");
    }
}

// 静态代理类型
class JdkProxy implements Service {

    private final Service service;

    // 构造器注入
    JdkProxy(Service service) {
        this.service = service;
    }


    @Override
    public String send(String msg) {
        System.out.println("代理运行前");
        service.send(msg);
        System.out.println("代理运行后");
        return msg;
    }
}


// 被代理接口
interface Service {
    String send(String msg);
}

// 被代理类
class ServiceImpl implements Service {

    @Override
    public String send(String msg) {
        System.out.println(msg);
        return msg;
    }
}
